package org.bbb.library1.model;

import java.util.Observable;

public class Book extends Observable {
	
	private String title = "no title";
	private String Author = "no author";
	//public String getTitle(){
	//	return title;
	//}
	
	public String getTitle() {
	    assert invariant() : "PRE: The invariant holds";
        return title;
	}


	public String getAuthor() {
		return Author;
	}


	

	//public void setTitle(String title){
	//	this.title = title;
	//}
	private boolean invariant() {
	    return isValidTitle(title);
	}
	
	
	private boolean isValidTitle(String title) {
	    return title != null && title.trim().length() > 0;
	}	
	
	public void setTitle(String title) {
	    assert invariant() : "PRE: The invariant holds";

	    if (!isValidTitle(title)) throw new IllegalArgumentException();

	    if (!this.title.equals(title)) {
	       this.title = title;
	       setChanged();
	    }

	    assert invariant() : "POST: The invariant holds";
	 }




	public void setAuthor(String author) {
		Author = author;
	}

}
